package com.example.thpool2;

import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {

        LockThreadPool pool = new LockThreadPool();
        pool.start();

        IntStream.rangeClosed(1, 200).forEach(i -> {
            pool.submitTask(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.printf("Thread %s: i = %d\n", Thread.currentThread().getName(), i);
            });
        });

        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

//        pool.shutdown();

        IntStream.rangeClosed(1, 2).forEach(i -> {
            pool.submitTask(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.printf("Thread %s: i = %d\n", Thread.currentThread().getName(), i);
            });
        });

    }
}
